package com.darren.euc.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonFormat;

@Entity
@Table(name = "euc_clues")
public class Clue implements Serializable {

	private static final long serialVersionUID = 7225410464606595171L;

	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	/**
	 * 联系人
	 */
	@Column(name = "contact", length = 30)
	private String contact;

	/**
	 * 联系电话
	 */
	@Column(name = "contact_number", length = 20)
	private String contactNumber;

	/**
	 * 微信
	 */
	@Column(name = "wechat", length = 50)
	private String wechat;
	
	/**
	 * 邮箱
	 */
	@Column(name = "email", length = 100)
	private String email;
	
	/**
	 * 意向省province id
	 */
	@Column(name = "province_id", length = 20)
	private String provinceId;
	
	/**
	 * 意向城市 city id
	 */
	@Column(name = "city_id", length = 20)
	private String cityId;
	
	/**
	 * 意向空间id
	 */
	@Column(name = "space_id", length = 20)
	private Integer spaceId;
	

	/**
	 * 意向产品类型
	 */
	@Column(name = "product_type_id")
	private Integer productTypeId;

	/**
	 * 渠道来源
	 */
	@Column(name = "source_channel_id")
	private Integer sourceChannelId;
	
	/**
	 * 预计入驻人数
	 */
	@Column(name = "people_count")
	private Integer peopleCount;
	

	/**
	 * 预约到访时间
	 */
	@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
	@Column(name = "visit_time")
	private Date visitTime;
	
	/**
	 * 预计入驻时间
	 */
	@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
	@Column(name = "enter_time")
	private Date enterTime;
	
	/**
	 * 关联客户ID
	 */
	@OneToOne 
    @JoinColumn(name="client_id" )
    private Client client;
	
	/**
	 * 领取人
	 */
	@ManyToOne(targetEntity = User.class, fetch = FetchType.EAGER)
	@JoinColumn(name = "process_person", referencedColumnName = "user_id")
	private User processPerson;
	
	@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
	@Column(name = "create_time",nullable=true,columnDefinition="datetime")
	private Date createTime;

	@Column(name = "create_user_id")
	private Integer createUserId;
	
	@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
	@Column(name = "last_modify_time",nullable=true,columnDefinition="datetime")
	private Date lastModifyTime;
	
	@Column(name = "last_modify_user_id")
	private Integer lastModifyUserId;
	
	
	@Column(name = "enable")
	private boolean enable = true;
	
	
//	@ElementCollection(targetClass=ClueFollow.class)
//	@JoinColumn(name="clue_id")
//	private List<ClueFollow> clueFollowList = new ArrayList<>(); 

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)//, mappedBy = "ClueFollow")
	@JoinColumn(name = "clue_id")
	private List<ClueFollow> clueFollowList = new ArrayList<ClueFollow>(); 
	
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)//, mappedBy = "ClueFollow")
	@JoinColumn(name = "clue_id")
	private List<ClueRemark> clueRemarkList = new ArrayList<ClueRemark>(); 
	
	@Transient
	private String clientClissification;
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getContact() {
		return contact;
	}

	public void setContact(String contact) {
		this.contact = contact;
	}

	public String getContactNumber() {
		return contactNumber;
	}

	public void setContactNumber(String contactNumber) {
		this.contactNumber = contactNumber;
	}

	public String getWechat() {
		return wechat;
	}

	public void setWechat(String wechat) {
		this.wechat = wechat;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getProvinceId() {
		return provinceId;
	}

	public void setProvinceId(String provinceId) {
		this.provinceId = provinceId;
	}

	public String getCityId() {
		return cityId;
	}

	public void setCityId(String cityId) {
		this.cityId = cityId;
	}

	public Integer getSpaceId() {
		return spaceId;
	}

	public void setSpaceId(Integer spaceId) {
		this.spaceId = spaceId;
	}

	public Integer getProductTypeId() {
		return productTypeId;
	}

	public void setProductTypeId(Integer productTypeId) {
		this.productTypeId = productTypeId;
	}

	public Integer getSourceChannelId() {
		return sourceChannelId;
	}

	public void setSourceChannelId(Integer sourceChannelId) {
		this.sourceChannelId = sourceChannelId;
	}

	public Integer getPeopleCount() {
		return peopleCount;
	}

	public void setPeopleCount(Integer peopleCount) {
		this.peopleCount = peopleCount;
	}
	
	
	public Date getVisitTime() {
		return visitTime;
	}

	public void setVisitTime(Date visitTime) {
		this.visitTime = visitTime;
	}

	public Date getEnterTime() {
		return enterTime;
	}

	public void setEnterTime(Date enterTime) {
		this.enterTime = enterTime;
	}
	
	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}

	public User getProcessPerson() {
		return processPerson;
	}

	public void setProcessPerson(User processPerson) {
		this.processPerson = processPerson;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Integer getCreateUserId() {
		return createUserId;
	}

	public void setCreateUserId(Integer createUserId) {
		this.createUserId = createUserId;
	}

	public Date getLastModifyTime() {
		return lastModifyTime;
	}

	public void setLastModifyTime(Date lastModifyTime) {
		this.lastModifyTime = lastModifyTime;
	}

	public Integer getLastModifyUserId() {
		return lastModifyUserId;
	}

	public void setLastModifyUserId(Integer lastModifyUserId) {
		this.lastModifyUserId = lastModifyUserId;
	}

	public boolean isEnable() {
		return enable;
	}

	public void setEnable(boolean enable) {
		this.enable = enable;
	}

	public List<ClueFollow> getClueFollowList() {
		return clueFollowList;
	}

	public void setClueFollowList(List<ClueFollow> clueFollowList) {
		this.clueFollowList = clueFollowList;
	}
	
	public List<ClueRemark> getClueRemarkList() {
		return clueRemarkList;
	}

	public void setClueRemarkList(List<ClueRemark> clueRemarkList) {
		this.clueRemarkList = clueRemarkList;
	}

	public String getClientClissification() {
		clientClissification = "暂无分类";
		ClueFollow clueFollowLast = null;
		for(ClueFollow clueFollow:clueFollowList){
			if(clueFollowLast == null ||clueFollowLast.getId() < clueFollow.getId()){
				clueFollowLast = clueFollow;
			}
		}
		if(clueFollowLast != null){
			clientClissification = clueFollowLast.getClientClassification().getClientLevel().getClientLevelName() + '-' + clueFollowLast.getClientClassification().getClientClassificationName();
		}		
		return clientClissification;
	}

	public void setClientClissification(String clientClissification) {
		this.clientClissification = clientClissification;
	}

	
}
